<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改员工')" />
	<th:block th:include="include :: jasny-bootstrap-css" />
	<th:block th:include="include :: select2-css" />
	<style>
	.layui-upload-drag{
		border: 1px solid #e5e6e7;
	}
	.layui-upload-drag .layui-icon{
		display: none;
	}
	.layui-upload-file{
		display: none;
	}
	</style>
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-employee-edit" th:object="${employee}">
            <input name="id" th:field="*{id}" type="hidden">
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">状态：</label>
                <div class="col-sm-8" th:with="type=${@dict.getType('employee_status')}" >
                	<div class="radio-box" th:each="dict : ${type}" >
                        <input type="radio" name="status" th:value="${dict.dictValue}" th:field="*{status}" th:id="${'status_'+dict.dictValue}" required>
                        <label th:for="${'status_'+dict.dictValue}" th:text="${dict.dictLabel}"></label>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">姓名：</label>
                <div class="col-sm-8">
                    <input name="name" th:field="*{name}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">性别：</label>
                <div class="col-sm-8" th:with="type=${@dict.getType('sys_user_sex')}">
                    <div class="radio-box" th:each="dict : ${type}" >
                        <input type="radio" name="sex" th:value="${dict.dictValue}" th:field="*{sex}" th:id="${'sex_'+dict.dictValue}" required>
                        <label th:for="${'sex_'+dict.dictValue}" th:text="${dict.dictLabel}"></label>
                    </div>
                </div>
            </div>
            
            <div class="form-group">    
                <label class="col-sm-3 control-label">手机号码：</label>
                <div class="col-sm-8">
                    <input name="phone" th:field="*{phone}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">民族：</label>
                <div class="col-sm-8">
                    <input name="nation" th:field="*{nation}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">籍贯：</label>
                <div class="col-sm-8">
                    <input name="nativePlace" th:field="*{nativePlace}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">出生日期：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        <input name="birthday" th:value="${#dates.format(employee.birthday, 'yyyy-MM-dd')}" class="form-control" placeholder="yyyy-MM-dd" type="text">
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">健康状况：</label>
                <div class="col-sm-8">
                    <input name="healthy" th:field="*{healthy}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">现居地：</label>
                <div class="col-sm-8">
                    <input name="address" th:field="*{address}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">教育背景：</label>
                <div class="col-sm-8" th:with="type=${@dict.getType('employee_education')}">
                    <div class="radio-box" th:each="dict : ${type}" >
                        <input type="radio" name="education" th:id="${'education_'+dict.dictValue}" th:value="${dict.dictValue}" th:field="*{education}">
                        <label th:for="${'education_'+dict.dictValue}" th:text="${dict.dictLabel}"></label>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">电子邮件：</label>
                <div class="col-sm-8">
                    <input name="email" th:field="*{email}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">照片：</label>
                <div class="col-sm-8">
					<div class="layui-upload-drag" id="imagePanel" >
					  <i class="layui-icon"></i>
					  <p>点击上传，或将文件拖拽到此处</p>
					  <div class="layui-hide" id="imageView">
					    <hr>
					    <img th:src="(${employee.image} == '') ? @{/img/unupload.jpeg} : @{${employee.image}}" alt="上传成功后渲染" style="max-width: 196px">
					  </div>
					</div>
                    <input name="image" th:field="*{image}" class="form-control" type="hidden">
                </div>
            </div>
            
            <div class="form-group">    
                <label class="col-sm-3 control-label">国籍：</label>
                <div class="col-sm-8">
                    <input name="nationality" th:field="*{nationality}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">身份证号码：</label>
                <div class="col-sm-8">
                    <input name="idCard" th:field="*{idCard}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">基本情况：</label>
                <div class="col-sm-8">
                    <textarea name="basicSituation" class="form-control">[[*{basicSituation}]]</textarea>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">特长描述：</label>
                <div class="col-sm-8">
                    <textarea name="speciality" class="form-control">[[*{speciality}]]</textarea>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">所属城市：</label>
                <div class="col-sm-8">
                    <select name="city" class="form-control " th:with="type=${@dict.getType('employee_city')}">
                        <option value="">--请选择--</option>
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{city}"></option>
                    </select>
                </div>
            </div>
            
            <div class="form-group">    
                <label class="col-sm-3 control-label">所属部门：</label>
                <div class="col-sm-8">
                    <input name="departmentId" id="departmentId" class="form-control" type="hidden" th:field="*{departmentId}">
                    <div class="input-group">
                    	<input name="departmentName" onclick="selectDeptTree()" id="departmentName" type="text" placeholder="请选择归属部门" class="form-control" th:field="*{departmentName}" required>
                        <span class="input-group-addon"><i class="fa fa-search"></i></span>
                    </div>
                </div>
            </div>
            
            <div class="form-group">    
                <label class="col-sm-3 control-label">职位：</label>
                <div class="col-sm-8">
                    <select name="position" class="form-control " >
                        <option value="">--请选择--</option>
                        <option th:each="post:${posts}" th:value="${post.postId}" th:text="${post.postName}" th:disabled="${post.status == '1'}" th:field="*{position}"></option>
                    </select>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
	<th:block th:include="include :: select2-js" />
    <script type="text/javascript">
        var prefix = ctx + "employee/employee";
        $("#form-employee-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-employee-edit').serialize());
            }else{
            	$.modal.msgError('表单填写错误');
            }
        }

        $("input[name='birthday']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });        
        
        function selectDeptTree() {
        	var treeId = $("#treeId").val();
        	var deptId = $.common.isEmpty(treeId) ? "100" : $("#treeId").val();
        	var url = ctx + "system/dept/selectDeptTree/" + deptId;
			var options = {
				title: '选择部门',
				width: "380",
				url: url,
				callBack: doSubmit
			};
			$.modal.openOptions(options);
		}
		
		function doSubmit(index, layero){
			var tree = layero.find("iframe")[0].contentWindow.$._tree;
			if ($.tree.notAllowParents(tree)) {
				var body = layer.getChildFrame('body', index);
    			$("#departmentId").val(body.find('#treeId').val());
    			$("#departmentName").val(body.find('#treeName').val());
    			layer.close(index);
			}
		}

		$(function() {
            $('#position').select2({
                placeholder: "请选择岗位",
                allowClear: true
            });
        })
        
		layui.use('upload', function(){
		  var $ = layui.jquery
		  	,upload = layui.upload;
		  //拖拽上传
		  upload.render({
		    elem: '#imagePanel'
		    ,url: '/common/upload'
		    ,done: function(res){
		      if(res.code==0){
		    	  layer.msg('上传成功');
		    	  $('#image').val(res.fileName);
		          layui.$('#imageView').removeClass('layui-hide').find('img').attr('src', res.fileName);
		      }else{
		    	  layer.msg('上传失败');
		      }
		      //console.log(res)
		    }
		  });
		  
		  $('.layui-upload-file').hide();
		        
		});      
    </script>
</body>
</html>